package com.rskj.cashbook.vo;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Date;


@Data
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = true)
public class CashBook extends BaseEntity {
    private BigDecimal amount;
    private Date consumerDate;
    private String remark;
    private BigDecimal consumerCount;
    private BigDecimal maxPay;
    private BigDecimal minPay;
    private String payUserId;
    private String forUserId;
    private String payUserName;
    private String forUserName;
    private String payWay;
    private String payPlat;
    private String entryType; // 入账来源
    private String month;
    private String quarter;
    private String week;
    
    private String billType; // 账单类型，对应Dict表的code
    private String billTypeName; // 账单类型名称，用于显示
    private String billCategory; // 账单分类：EXPENSE(支出)、INCOME(收入)、LOAN(借贷)、TRANSFER(转账)
    private Integer isIncome; // 是否为收入类型
    private String relatedBillId; // 关联账单ID，用于借贷和转账的关联
    

    public void setBillType(String billType) {
        this.billType = billType;
    }
    
    /**
     * 获取金额的绝对值（用于显示）
     */
    public BigDecimal getAmountAbs() {
        return this.amount != null ? this.amount.abs() : BigDecimal.ZERO;
    }
    
    /**
     * 获取带符号的金额（支出为负，收入为正）
     */
    public BigDecimal getSignedAmount() {
        if (this.amount == null) {
            return BigDecimal.ZERO;
        }
        
        // 根据账单分类判断正负
        if ("EXPENSE".equals(this.billCategory) || "TRANSFER_OUT".equals(this.billType) || "LEND".equals(this.billType)) {
            return this.amount.negate();
        } else {
            return this.amount;
        }
    }
}
